package cj.web.kly.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.kly.domain.News;
import cj.web.kly.domain.Subject;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SubjectDAO{
	
	@SQL("SELECT a.id,a.type,a.columnsId,a.subjectId,a.subjectColumnsId,a.title,a.abstractInfor,a.carouselImage,a.source,a.author,a.status,a.releaseState,a.releaseAt,a.isTop,a.stickAt,a.pvNum,a.pvNumFinal,b.name as columnsName,b.id as treeIdIn FROM News a join Columns b on a.columnsId=b.id WHERE a.id NOT IN (##(:ids)) AND a.deleteFlag=1 and a.columnsId is not null #if(:t.treeIdIn != null){ AND a.columnsId in (##(:t.treeIdIn)) } #if(:t.title != null){ AND (a.title LIKE '%##(:t.title)%' or a.content LIKE '%##(:t.content)%') } ORDER BY a.updateAt DESC LIMIT :t.start,:t.length ")
    List<News> queryNewslis(@SQLParam("t") News news,@SQLParam("ids") String not_in_id);
		
	@SQL("SELECT count(1) FROM News WHERE id NOT IN (##(:ids)) AND deleteFlag=1 and columnsId is not null #if(:t.treeIdIn != null){ AND columnsId in (##(:t.treeIdIn)) } #if(:t.title != null){ AND (title LIKE '%##(:t.title)%' or content LIKE '%##(:t.content)%') } " )
    int queryNewslisSize(@SQLParam("t") News news,@SQLParam("ids") String not_in_id);
	
	@SQL("SELECT * FROM Subject WHERE deleteFlag=1 ORDER BY orderNo ")
    List<Subject> queryAll();
	
	@SQL("SELECT * FROM Subject WHERE deleteFlag=1 #if(:t.name != null){ AND name LIKE '%##(:t.name)%' } ORDER BY orderNo LIMIT :t.start,:t.length ")
    List<Subject> query(@SQLParam("t") Subject subject);
		
	@SQL("SELECT count(1) FROM Subject WHERE deleteFlag=1 #if(:t.name != null){ AND name LIKE '%##(:t.name)%' }" )
    int querySize(@SQLParam("t") Subject subject);
    
    @SQL("SELECT * FROM Subject WHERE id=:1")
    Subject queryById(int id);
    
    @SQL("INSERT INTO Subject ("
			        		+ "type,"
			        		+ "name,"
			        		+ "en,"
			        		+ "carouselImageMin,"
			        		+ "carouselImage,"
			        		+ "descs,"
			        		+ "status,"
			        		+ "orderNo,"
			        		+ "deleteFlag,"
			        		+ "createUser,"
			        		+ "createAt,"
			        		+ "updateUser,"
			        		+ "updateAt"
							+") VALUES ("
							+ ":t.type,"
							+ ":t.name,"
							+ ":t.en,"
							+ ":t.carouselImageMin,"
							+ ":t.carouselImage,"
							+ ":t.descs,"
							+ ":t.status,"
							+ ":t.orderNo,"
							+ "1,"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser,"
							+ "now()) ")
    void create(@SQLParam("t") Subject subject);
	
	@SQL("UPDATE Subject SET type=:t.type,name=:t.name,en=:t.en,carouselImageMin=:t.carouselImageMin,carouselImage=:t.carouselImage,descs=:t.descs,status=:t.status,orderNo=:t.orderNo,updateUser=:t.updateUser,updateAt=now() WHERE id=:t.id")
    void update(@SQLParam("t") Subject subject);
    
    @SQL("UPDATE Subject SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("UPDATE Subject SET status=0 WHERE id=:1")
    void updateStatusById(int id);
}